package net.comm.group.db;

import org.sakaiproject.db.api.iServiceSql;


/**
 * methods for accessing user data in a database.
 */
public class GFollForumServiceSqlMysql implements iServiceSql
{
	/**
	 * 返回根据主键删除语句
	 */
	public String getDeleteSql()
	{
		return "delete from GFollForum where GFollowID=? and gupFollID=? ";
	}

	/**
	 * 返回根据主键删除语句
	 */
	public String getDelbygForumIDSql()
	{
		return "delete from GFollForum where gForumID=? ";
	}
	
	/**
	 * 返回插入语句
	 */
	public String getInsertSql()
	{
		return "insert into GFollForum (  gFollowID, gupFollID, gForumID, groupID, title," +
				" content, fileID, upUserID, userID, IP,mTime " +
				") values (?,?,?,?,?,?,?,?,?,?,?)";
	}
	
	/**
	 * 返回根据主键修改语句
	 */
	public String getUpdateSql()
	{
		return "update GFollForum  set gForumID=?, groupID=?, title=?," +
				" content=?, fileID=?, upUserID=?, userID=?, IP=?, mTime=? " +  
				" where GFollowID=? and gupFollID=? ";
	}

	/**
	 * 返回根据主键查询语句
	 */
	public String getbykeySql()
	{
		return "select gFollowID, gupFollID, gForumID, groupID, title," +
				" content, fileID, upUserID, userID, IP,mTime " +
				" from GFollForum where GFollowID=? and gupFollID=? ";
	}
	
	/**
	 * 返回根据会员ID查询语句 
	 */
	public String getByUserIDSql()
	{
		StringBuffer sb =  new StringBuffer("select gFollowID, gupFollID, gForumID, groupID, title," +
				" content, fileID, upUserID, userID, IP,mTime " +
				" from GFollForum");
		
		sb.append(" where GForumID in (select GForumID from GForum where userID=? ) " +
				"and Mtime >= ? Order by Mtime Desc ");
				
		return sb.toString();
	}
	
	/**
	 * 返回根据会员ID查询语句 
	 */
	public String getByOnlyUserIDSql()
	{
		StringBuffer sb =  new StringBuffer("select gFollowID, gupFollID, gForumID, groupID, title," +
				" content, fileID, upUserID, userID, IP,mTime " +
				" from GFollForum");
		
		sb.append(" where userID=? or upUserID=? limit 2 ");
				
		return sb.toString();
	}

	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecbyPageSql()
	{
	
		StringBuffer sb =  new StringBuffer("select gFollowID, gupFollID, gForumID, groupID, title," +
				" content, fileID, upUserID, userID, IP,mTime " +
				" from GFollForum ");
		
		sb.append(" where gForumID=? ");
		sb.append(" limit ?, ? ");
				
		return sb.toString();	
	}	
	
	/**
	 * 返回所有记录数
	 */
	public String getCountSql1()
	{
		return "select count(*) as COUNT from GFollForum where gForumID=? ";
	}


	/**
	 * 返回根据查询条件的记录数
	 */
	public String getCountSql2()
	{
		return "select count(*) as COUNT from GFollForum where UserID=? ";
	}

	/**
	 * 返回根据跟帖序号查询语句 
	 */
	public String getByFollIDSql()
	{
		StringBuffer sb =  new StringBuffer("select gFollowID, gupFollID, gForumID, groupID, title," +
				" content, fileID, upUserID, userID, IP,mTime " +
				" from GFollForum");
		
		sb.append(" where gFollowID=?  Order by gupFollID desc ");
				
		return sb.toString();
	}	
	
	/**
	 * @see net.comm.job.db.iServiceSql.impl.UserServiceSql#getMaxInputsForSelectWhereInQueries()
	 */
	public int getMaxInputsForSelectWhereInQueries() {
		// For Oracle, the maximum supported number of expressions in a list is 1000. 
		return 1000;
	}
}
